﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickupSpawn : MonoBehaviour
{
    public GameObject[] pickups;
    public float L, R;
    public float lowerHealth, highHealth;
    public float deliverTime;
    public HealthBar heal;
    void Start()
    {
        heal = GameObject.Find("HealthBar").GetComponent<HealthBar>();
        StartCoroutine(DeliverPickups());
    }
    IEnumerator DeliverPickups()
    {
        while(true){
            yield return new WaitForSeconds(deliverTime);
            Vector3 dropPos = transform.position + Vector3.right * Random.Range(L, R);
            if(heal.health >= highHealth){
                Instantiate(pickups[0], dropPos, Quaternion.identity);
            }
            else if(heal.health <= lowerHealth){
                Instantiate(pickups[1], dropPos, Quaternion.identity);
            }
            else{
                Instantiate(pickups[Random.Range(0, pickups.Length)], dropPos, Quaternion.identity);
            }
        }
    }
}
